Using the colormap package

  • You can use the class Colormap as shown below
  • You can use the cmap_builder function and test_cmap function as well (see end of notebook)

In [1]:
%pylab inline
from colormap import Colormap


Populating the interactive namespace from numpy and matplotlib

In [2]:
c = Colormap()

In [3]:
cmap = c.cmap('cool')

In [4]:
# let us see what it looks like
c.test_colormap(cmap)



In [5]:
#Would be nice to plot a bunch of colormap to pick up one interesting
c.plot_colormap('diverging')



In [6]:
c.plot_colormap(c.misc)



In [7]:
c.plot_colormap(c.qualitative)



In [8]:
c.plot_colormap(c.sequentials)



In [9]:
c.plot_colormap(c.sequentials2)



In [10]:
# This list is implemented in colormap package itself
c.plot_colormap(c.diverging_black)


Well, I have not found the one I wanted...I wanted from red to white to green


In [11]:
mycmap = c.cmap_linear('red', 'white', 'green(w3c)')
c.test_colormap(mycmap)



In [12]:
mycmap = c.cmap_bicolor('red', 'green(w3c)')
c.test_colormap(mycmap)



In [13]:
# there is also 2 extra maps from R
mycmap = c.get_cmap_heat()
c.test_colormap(mycmap)



In [18]:
# color can be given a a name available in 
import colormap.xfree86 as colors

In [20]:
list(colors.XFree86_colors.keys())[0:5]


Out[20]:
['Light Sea Green', 'Pale Turquoise', 'White Smoke', 'Tomato', 'Rosy Brown']

In [22]:
#or 
list(colors.XFree86_colors.values())[0:5]


Out[22]:
['#20B2AA', '#AFEEEE', '#F5F5F5', '#FF6347', '#BC8F8F']

In [23]:
# or as RGB, HLS, HSV, YUX, Hexa format
from colormap import Color

In [24]:
co = Color('white')

In [25]:
co.hex


Out[25]:
'#FFFFFF'

In [26]:
mycmap = c.cmap_linear('red', '#FFFFFF', 'green(w3c)')
c.test_colormap(mycmap)



In [27]:
# Conversion between colors
c = Color('red')
c.rgb


Out[27]:
(1.0, 0.0, 0.0)

In [28]:
c.hls


Out[28]:
(0.0, 0.5, 1.0)

In [29]:
c.hex


Out[29]:
'#FF0000'

In [30]:
print(c)


Color Red
  hexa code: #FF0000
  RGB code: (1.0, 0.0, 0.0)
  RGB code (un-normalised): [255.0, 0.0, 0.0]

  HSV code: (0.0, 1.0, 1.0)
  HSV code: (un-normalised) 0.0 100.0 100.0

  HLS code: (0.0, 0.5, 1.0)
  HLS code: (un-normalised) 0.0 50.0 100.0


Using cma_builder and test_cmap

Instead of using the Colormap class, you can also use the cmap_builder alias function andthe test_cmap function


In [31]:
from colormap import cmap_builder, test_cmap

In [26]:
mycm = cmap_builder('red', 'white', 'green')
test_cmap(mycm)



In [ ]: